<?php 
    include_once 'buslibs/products.php';
    $product=NULL;
    $productId=NULL;
    

    if(!isset($_GET['productId']) || $_GET['productId']==''){
        echo "Invalid product id";
        exit;
    }
    else
    {
        $productId=$_GET['productId'];
        $product=read_product($productId);
        if(!$product){
            echo "Το προϊόν δεν βρέθηκε";
            exit;
        }

    echo "<div style='float:right;width:150px;'>";
include_once 'showimages.php';
    echo "</div>";

        $r=  user_read_id($product->idOwner);
        echo "Απο : <a href='index.php?action=profile&user=$r->username '>$r->username</a></br>";
        echo "<h2>{$product->title} </h2> <br/>";
        echo "<p>Τιμή :{$product->price}</p>";
        if (isset($product->description)){
            echo "<h2>Λεπτομέριες</h2>";
            echo "<p>{$product->description}</p>";
        }
        echo "<p>Ποσότητα : {$product->quantity}</p>";
        if(key_exists('role',$_SESSION))
            if($_SESSION['role']=='admin' || $_SESSION['idUsers']==$product->idOwner)
                {?><form method="POST" action="index.php?action=deleteproduct">
                    <input type="hidden" name="deleteProductId" value=<?php echo $product->idProducts;?>>
                    <input type="submit" value="Διαγραφή">
                </form>
                <?php }   
    }
    
if(isset($_SESSION['idUsers'])){ 
    if($_SESSION['idUsers']!=$product->idOwner){?>
        <form method="POST" action="index.php?action=buyproduct" >
        <input type="hidden" name="productIdbuy" value="<?php echo $product->idProducts; ?>">
        <input type="submit" name="buybutton" value="Αγορά">
        </form>

<?php }

    if($_SESSION['idUsers']==$product->idOwner)  include 'imageupload.php';
    }
?>

